package io;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/*
RandomAccessFile可以实现向已存在的文件追加内容的功能
 */
public class RandomAccessFileTest {
    public static void main(String[] args) throws IOException {
        RandomAccessFile randomAccessFile = new RandomAccessFile("..\\shiqiCoreClone\\src\\main\\java\\io\\RandomAccessFileTest.java","r");
        System.out.println("RandomAccessFile的文件指针的初始位置：" + randomAccessFile.getFilePointer());
        //移动文件记录指针
        randomAccessFile.seek(300);
        byte[] bytes = new byte[1024];
        int hasRead = 0;
        while ((hasRead = randomAccessFile.read(bytes)) > 0) {
            //将字节数组转化为字符串
            System.out.println(new String(bytes,0,hasRead));
        }
        randomAccessFile.close();
    }
}
